package com.company.cuobuliao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.company.cuobuliao.R;
import com.company.cuobuliao.model.ClassStudent;
import com.company.cuobuliao.view.ThinFontTextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Oreo on 2017/8/23.
 */

public class ScanResultAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private Context context;
    private List<ClassStudent> list = new ArrayList<>();

    public ScanResultAdapter(Context context, List<ClassStudent> list) {
        this.list = list;
        this.context = context;
        this.mInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = mInflater.inflate(R.layout.list_item_scanresult, viewGroup, false);
            holder.lilyItem = (LinearLayout) view.findViewById(R.id.lilyItem);
            holder.tvNum = (ThinFontTextView) view.findViewById(R.id.tvNum);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        if (i % 2 == 1) {
            holder.lilyItem.setBackgroundResource(R.color.gray_bg2);
        } else {
            holder.lilyItem.setBackgroundResource(R.color.gray_bg);
        }
        holder.tvNum.setText((i + 1) + "");
//        holder.tvTitle.setText(list.get(i).getTitle());
        return view;
    }

    static class ViewHolder {
        private ThinFontTextView tvTitle;
        private ThinFontTextView tvNum;
        private ImageView ivPic;
        private ImageView ivEnd;
        private LinearLayout lilyItem;
    }
}